import 'dart:math';
import 'package:get/get.dart';

class DiscoverIndexController extends GetxController {
  DiscoverIndexController();

  // 当前Tab索引 (0-任务大厅, 1-接单大厅)
  RxInt currentTabIndex = 0.obs;

  // 头像列表
  final List<String> avatarUrls = [
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_1.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_2.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_3.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_4.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_5.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_6.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_7.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_8.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_9.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_10.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_11.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_12.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_13.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_14.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_15.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_16.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_17.webp',
    'https://bai-ying.oss-cn-qingdao.aliyuncs.com/image/user_test/user_18.webp',
  ];

  _initData() {
    update(["discover_index"]);
  }

  // 切换Tab
  void switchTab(int index) {
    currentTabIndex.value = index;
  }

  // 获取随机头像
  String getRandomAvatar() {
    return avatarUrls[Random().nextInt(avatarUrls.length)];
  }

  // 跳转到商单详情页
  void goToTaskDetail(Map<String, dynamic> taskData) {
    Get.toNamed(
      '/discover_discover_detial',
      arguments: taskData,
    );
  }

  @override
  void onReady() {
    super.onReady();
    _initData();
  }
}
